package com.admin.sys.base.websocket.web;
import com.admin.sys.base.entity.ResultInfo;
import com.admin.sys.base.websocket.entity.SessionUser;
import com.admin.sys.base.websocket.service.SessionService;
import com.admin.sys.base.module.message.entity.SysMessage;
import com.admin.sys.base.module.message.service.SysMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/socket")
public class WebSocketController {
    @Autowired
    private SessionService sessionService;
    @Autowired
    private SysMessageService sysMessageService;

    //获取客户端聊天用户
    @RequestMapping("/getChatUserList")
    public ResultInfo getClientUserList(String userType,String roleCode) {
        if("front".equals(userType)){
            List<SessionUser> frontList = sessionService.getFrontList();
            return ResultInfo.ok("获取前台用户列表成功", frontList);
        }else if("admin".equals(userType)){
            List<SessionUser> adminList = sessionService.getAdminList(roleCode);
            return ResultInfo.ok("获取后台用户列表成功", adminList);
        }else{
            List<SessionUser> allList = sessionService.getAllList();
            return ResultInfo.ok("获取全部用户列表成功", allList);
        }
    }

    //提交聊天信息
    @RequestMapping("/subChat")
    public ResultInfo subChat(SysMessage sysMessage){
        sysMessage.setType("聊天");
        sysMessageService.insert(sysMessage);
        return ResultInfo.ok("获取列表成功");
    }

    //获取聊天记录
    @RequestMapping("/getChatList")
    public ResultInfo getChatList(SysMessage sysMessage){
        sysMessage.setType("聊天");
        List<SysMessage> list = sysMessageService.getList(sysMessage);
        return ResultInfo.ok("获取列表成功",list);
    }

}